package com.example.yiwei.crm.view.frament.customerDetailedMenuPackage;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.yiwei.crm.R;
import com.example.yiwei.crm.data.GetCustumer;
import com.example.yiwei.crm.entity.CustomerMessageEntity;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/12.
 */

public class BaseFragment extends Fragment {
    TextView txt_name,txt_manager,txt_age,txt_gender,txt_IDNumber,txt_medical_category,txt_security_numbers,
        txt_xzqy,txt_home_address,txt_manager1,txt_manager2;
    CustomerMessageEntity customer;
    String result;
    List<Map<String,String>> customerSpinner;
    String medical_class;
    Button button;
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootview=inflater.inflate(R.layout.fragment_customer_detailed_base,container,false);
        txt_name= (TextView) rootview.findViewById(R.id.fragment_customer_base_customerName);
        txt_manager= (TextView) rootview.findViewById(R.id.fragment_customer_base_manager);
        txt_age= (TextView) rootview.findViewById(R.id.fragment_customer_base_customerAge);
        txt_gender= (TextView) rootview.findViewById(R.id.fragment_customer_base_customergender);
        txt_IDNumber= (TextView) rootview.findViewById(R.id.fragment_customer_base_customer_IDNumber);
        txt_medical_category= (TextView) rootview.findViewById(R.id.fragment_customer_base_medical_category);
        txt_security_numbers= (TextView) rootview.findViewById(R.id.fragment_customer_base_security_numbers);
        txt_xzqy= (TextView) rootview.findViewById(R.id.fragment_customer_base_xzqy);
        txt_home_address= (TextView) rootview.findViewById(R.id.fragment_customer_base_home_address);
        txt_manager1= (TextView) rootview.findViewById(R.id.frm_customer_detailed_base_txt_manager);
        txt_manager2= (TextView) rootview.findViewById(R.id.frm_customer_line);
        if("lqkh".equals(getActivity().getIntent().getStringExtra("tag"))){
            txt_manager1.setText("院内负责人");
        }
        customer = GetCustumer.get();
//        if (customer.getClient_Manager()==0){
//            txt_manager.setVisibility(View.GONE);
//            txt_manager1.setVisibility(View.GONE);
//            txt_manager2.setVisibility(View.GONE);
//        }
//        button= (Button) rootview.findViewById(R.id.fragment_customer_detailed_base_updata_btn);
//        button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(getActivity(), UpdateCustomerBaseMessageActivity.class);
//                startActivity(intent);
//            }
//        });
        initData();
        return rootview;
    }

    private void initData() {
        txt_name.setText(customer.getClient_name());
        txt_manager.setText(customer.getClient_manager_name());
        txt_age.setText(String.valueOf(customer.getClient_age()));
        if (customer.getClient_gender()!=0){
            if (customer.getClient_gender()==1){
                txt_gender.setText("男");
            }else if (customer.getClient_gender()==2){
                txt_gender.setText("女");
            }
        }else{
            txt_gender.setText("性别未填写");
        }
        txt_IDNumber.setText(customer.getIDNumber());
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                final customerDao customerdao=new customerDaoImpl();
//                result = getSpinnerClass.getSpinner();
//                customerSpinner=customerdao.querySpinnerContent(result,6);
//                for (int i = 0;i<customerSpinner.size();i++){
//                    if (String.valueOf(customer.getMedical_class_id()).equals(customerSpinner.get(i).get("YBLX01"))){
//                        medical_class=customerSpinner.get(i).get("YBLX02");
//                    }
//                }
//                getActivity().runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        if (medical_class!=null){
//                            txt_medical_category.setText(medical_class);
//                        }
//                    }
//                });
//
//            }
//        }).start();
        txt_security_numbers.setText(customer.getSecurity_numbers());
        if (customer.getPname()!=null) {
            txt_xzqy.setText(customer.getPname() + customer.getCname() + customer.getAname());
        }
        txt_home_address.setText(customer.getClient_Address());
        txt_medical_category.setText(customer.getMedical_class());
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
    }
}
